// vue的权限模块
import { constantRoutes, asyncRoutes } from '@/router'
// 定义他们三个的变量
const state = { // 状态
  rotes: constantRoutes // 所有人默认的静态路由
}
const mutations = { // 修改数据
  setRoutes (state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = { // 处理异步
// 筛选权限路由
  filterRoutes (context, menus) {
    // 定义一个空数组
    const routes = []
    menus.forEach(key => {
      routes.push(...asyncRoutes.filter(item => item.name === key))
    })
    context.commit('setRoutes', routes) // 将动态路由提交给setRoutes
    return routes
  }
}
// 导出一个对象
export default {
  // 命名空间
  namespaced: true,
  state,
  mutations,
  actions
}
